package com.lastproject.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedProperty;

import com.lastproject.ejb.dao.QuestionOptionDAORemote;

// Lazar Mihnea

public class QuestionStatsDTO implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int id;
	private String text;
	private int idSurvey;
	private List<Integer> listOption;

	private float nbTotalAnswers;
	private float[] nbAnswers;

	@ManagedProperty(value = "#{questionDTO}")
	QuestionDTO questionDTO;

	@ManagedProperty(value = "#{questionOptionStatsListDTO}")
	private List<QuestionOptionStatsDTO> questionOptionStatsList;

	private QuestionOptionStatsDTO[] questionOptionStatsArr;

	@EJB
	private QuestionOptionDAORemote questionOptionDAOr;

	public QuestionStatsDTO() {
		super();
		// TODO Auto-generated constructor stub
	}

	public QuestionStatsDTO(int id, String text, int idSurvey,
			List<Integer> listOption) {
		super();
		this.id = id;
		this.text = text;
		this.idSurvey = idSurvey;
		this.listOption = listOption;
	}

	public QuestionStatsDTO(QuestionDTO questionDTO) {
		super();
		this.questionDTO = questionDTO;
		this.id = questionDTO.getId();
		this.text = questionDTO.getText();
		this.idSurvey = questionDTO.getSurveyId();
		if (questionDTO.getOptions() != null)
			for (QuestionOptionDTO q : questionDTO.getOptions()) {
				this.listOption.add(q.getId());
			}
		// this.listOption = questionDTO.getOptions();

		// this.setQOStatsList(questionDTO);

	}

	public void setQOStatsList(QuestionDTO questionDTO) {

		int idQ = questionDTO.getId();

		questionOptionStatsList = new ArrayList<QuestionOptionStatsDTO>();

		// List<QuestionOptionDTO> qoDTOList = new
		// ArrayList<QuestionOptionDTO>();

		QuestionOptionStatsDTO qoStatsObj;

		System.out.println("QuestionStatsDTO question ID: " + idQ);
		try {
			System.out.println("QStatDTO - A INTRAT IN TRY BLOCK");
			List<QuestionOptionDTO> qoDTOList = questionOptionDAOr
					.getQuestionOptionListByQuestionId(idQ);

			System.out.println("QuestionStatsDTO size of qoDTOList: "
					+ qoDTOList.size());

			for (int i = 0; i < qoDTOList.size(); i++) {
				qoStatsObj = new QuestionOptionStatsDTO(qoDTOList.get(i));
				questionOptionStatsList.add(qoStatsObj);
			}

		} catch (NullPointerException e) {
			e.printStackTrace();
		}

		System.out.println("QuestionStatsDTO size of questionOptionStatsList: "
				+ questionOptionStatsList.size());

	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public int getIdSurvey() {
		return idSurvey;
	}

	public void setIdSurvey(int idSurvey) {
		this.idSurvey = idSurvey;
	}

	public List<Integer> getListOption() {
		return listOption;
	}

	public void setListOption(List<Integer> listOption) {
		this.listOption = listOption;
	}

	public List<QuestionOptionStatsDTO> getQuestionOptionStatsList() {
		return questionOptionStatsList;
	}

	public void setQuestionOptionStatsList(
			List<QuestionOptionStatsDTO> questionOptionStatsList) {
		this.questionOptionStatsList = questionOptionStatsList;
	}

	public QuestionDTO getQuestionDTO() {
		return questionDTO;
	}

	public void setQuestionDTO(QuestionDTO questionDTO) {
		this.questionDTO = questionDTO;
	}

	public QuestionOptionStatsDTO[] getQuestionOptionStatsArr() {
		return questionOptionStatsArr;
	}

	public void setQuestionOptionStatsArr(
			QuestionOptionStatsDTO[] questionOptionStatsArr) {
		this.questionOptionStatsArr = questionOptionStatsArr;
	}

	public float getNbTotalAnswers() {
		return nbTotalAnswers;
	}

	public void setNbTotalAnswers(float nbTotalAnswers) {
		this.nbTotalAnswers = nbTotalAnswers;
	}

	public float[] getNbAnswers() {
		return nbAnswers;
	}

	public void setNbAnswers(float[] nbAnswers) {
		this.nbAnswers = nbAnswers;
	}

	public void setAnswerListSize(int size) {
		this.nbAnswers = new float[size];
	}

	public void setAnswerInList(int index, float value) {
		this.nbAnswers[index] = value;
	}

	public float getAnswerInList(int index) {
		return nbAnswers[index];
	}

}
